package com.line.myprojectservice.controller;

import com.line.myprojectservice.dto.NoteDto;
import com.line.myprojectservice.service.NoteService;
import com.line.myprojectservice.utils.Pager;
import com.line.myprojectservice.utils.ResponseUtil;
import com.line.myprojectservice.vo.NoteVo;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/forum")
public class NoteController {

    final NoteService noteService;

    public NoteController(NoteService noteService) {
        this.noteService = noteService;
    }

    /**
     * 分页查询
     */
    @GetMapping
    public ResponseUtil findPage(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer size) {
        Pager<NoteVo> pager = noteService.findByPager(page, size);
        return ResponseUtil.success(pager);
    }

    /**
     * 新增
     */
    @PostMapping
    public ResponseUtil add(@RequestBody NoteDto noteDto) {
        noteService.addNote(noteDto);
        return ResponseUtil.success();
    }


    /**
     * 热门回答
     */
    @GetMapping("/hot")
    public ResponseUtil getHotAnswer() {

        return ResponseUtil.success( noteService.getHotAnswer());
    }

//    /**
//     *更新
//     */
//    @PutMapping
//    public ResponseUtil update(@RequestBody Book Book) {
//        bookMapper.updateById(Book);
//        return ResponseUtil.success();
//    }

    //    /**
//     *删除
//     */
//    @DeleteMapping("/{id}")
//    public ResponseUtil delete(@PathVariable Integer id) {
//        bookMapper.deleteById(id);
//        return ResponseUtil.success();
//    }

}
